<?php

Yii::import('common.models.db._base.BaseDeliveryMoveDetailModel');

class DeliveryMoveDetailModel extends BaseDeliveryMoveDetailModel
{
	const DETAIL_TYPE='Bảng kê chi tiết';
	const STATUS_0 ='Phân công phát';
	const STATUS_1 ='Chuyển tiếp';
	const STATUS_2 ='Chuyển hoàn';
	const STATUS_3 ='Hoàn thành';
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
	public function attributeLabels() {
		return array(
				'id' => Yii::t('DeliveryModule.main', 'ID'),
				'code' => Yii::t('DeliveryModule.main', 'Code'),
				'type' => Yii::t('DeliveryModule.main', 'Type'),
				'user_id' => Yii::t('DeliveryModule.main', 'User'),
				'order_ticket_id' => Yii::t('DeliveryModule.main', 'Order Ticket'),
				'office_id' => Yii::t('DeliveryModule.main', 'Office'),
				'office_next' => Yii::t('DeliveryModule.main', 'Office Forward'),
				'office_user_id' => Yii::t('DeliveryModule.main', 'Office User Take'),
				'note' => Yii::t('DeliveryModule.main', 'Note'),
				'weight' => Yii::t('DeliveryModule.main', 'Weight'),
				'status' => Yii::t('DeliveryModule.main', 'Status'),
				'reason' => Yii::t('DeliveryModule.main', 'Reason'),
				'updated_datetime' => Yii::t('DeliveryModule.main', 'Updated Datetime'),
				'created_datetime' => Yii::t('DeliveryModule.main', 'Created Datetime'),
		);
	}
	public function getLastStatus($orderId)
	{
		$sql = "SELECT count(*) as number FROM delivery_move_detail WHERE order_ticket_id=$orderId AND status=3";
		return Yii::app()->db->createCommand($sql)->queryScalar();
	}
}